package com.example.controller;

import com.example.common.Result;
import com.example.pojo.dto.HeadDto;
import com.example.pojo.entity.Head;
import com.example.pojo.entity.Head;
import com.example.service.HeadService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/head")
public class HeadController {

    @Resource
    HeadService headService;

    @PostMapping("/add")
    public Result add(@RequestBody HeadDto headDto) {
        headService.insert(headDto);
        return Result.success();
    }

    /*
      修改用户
     */
    @PutMapping("/update")
    public Result update(@RequestBody Head head){
        headService.updateById(head);
        return Result.success();
    }


    /*
         删除用户
         */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        headService.removeById(id);
        return Result.success();
    }



    //批量删除用户

    @DeleteMapping("/delete/batch")
    public Result batchDelete(@RequestBody List<Integer> ids){
        headService.removeBatchByIds(ids);
        return Result.success();
    }


    // 查询所有用户

    @GetMapping("/selectAll")
    public Result selectAll(){
        List<Head> list = headService.list();
        return Result.success(list);
    }


    //根据ID查询用户

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        HeadDto headDto = headService.getById(id);
        return Result.success(headDto);
    }


    // 分页查询用户

    @GetMapping("/selectByPage")
    public Result selectByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "") String name,
            @RequestParam(defaultValue = "") String title,
            @RequestParam(defaultValue = "") String museum,
            @RequestParam(defaultValue = "") String activity) {
        PageInfo<HeadDto> pageInfo = headService.selectByPage(pageNum, pageSize, name, title, museum, activity);
        return Result.success(pageInfo);
    }

   /* @GetMapping("/selectByName")
    public Result selectByPageAll(
    })
*/

}
